const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  mode: 'development',
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].bundle.js',
    clean: true
  },
  devServer: {
    static: './dist',
  },
  // 错误追踪记录
  devtool: 'inline-source-map',
  plugins: [
    new HtmlWebpackPlugin({
      // template: './src/index.html',
      // filename: 'index.html',
      title: 'webpack-demo'
    })
  ],
  module: {
    // 添加loader
    rules: [
      {
        test: /\.less$|\.scss$|\.css$/,
        use: ['style-loader', 'css-loader', 'less-loader'],
      },
      {
        test: /\.(png|jpg|gif|jpeg|svg)$/i,
        type: 'asset/resource',
      }
    ]
  }
}